package com.longdaji.decoration.ui.main.home;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.LoopPagerAdapter;
import com.longdaji.decoration.R;
import com.longdaji.decoration.data.bean.GoodsChosensBean;
import com.longdaji.decoration.ui.bannerImage.BannerImageActivity;
import com.longdaji.decoration.utils.ImageUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by longtao on 2018/2/1.
 */

public class LooperAdapter extends LoopPagerAdapter {
    private Context mContext;
    private List<GoodsChosensBean.GoodsChosensImg> mAdList;

    public LooperAdapter(Context context, RollPagerView viewPager, List<GoodsChosensBean.GoodsChosensImg> adList) {
        super(viewPager);
        this.mContext = context;
        if (adList == null) {
            adList = new ArrayList<>();
        }
        this.mAdList = adList;

    }

    public void setData(List<GoodsChosensBean.GoodsChosensImg> adList) {
        if (mAdList == null) {
            mAdList = new ArrayList<>();
        }
        mAdList.clear();
        mAdList.addAll(adList);
        notifyDataSetChanged();
    }

    @Override
    public View getView(ViewGroup container, final int position) {
        View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_banner, container, false);
        ImageView imageView = view.findViewById(R.id.iv_ad_pic);
//        TextView adTitle = view.findViewById(R.id.tv_ad_title);
//        TextView adContent = view.findViewById(R.id.tv_ad_content);

        ImageUtil.loadImage(mContext, mAdList.get(position).getImgAddress(), imageView);

        //GlideUtils.loadImage(mContext, mAdList.get(position).getImgAddress(), imageView, null, R.drawable.no_banner, R.drawable.no_banner);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = BannerImageActivity.getStartIntent(mContext);
                intent.putExtra("title","精选图片");
                intent.putExtra("image", mAdList.get(position).getBannerImgAddress()


                );
                mContext.startActivity(intent);
            }
        });
        return view;
    }

    @Override
    public int getRealCount() {
        return mAdList.size();
    }
}
